package com.cunshe.web.manage;

import com.cunshe.common.ResponseVO;
import com.cunshe.config.annotation.Login;
import com.cunshe.domain.DataDown;
import com.cunshe.entity.vo.DataDownInsertVO;
import com.cunshe.entity.vo.DataDownUpdateVO;
import com.cunshe.service.DataDownService;
import com.cunshe.web.BaseController;
import com.sunkee.commons.utils.ConvertUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 资料下载
 * @author xiao
 */
@Api(tags = "资料下载")
@Login
@RestController
@RequestMapping(value = "/manage/dataDown")
public class DataDownController extends BaseController {

    @Autowired
    private DataDownService dataDownService;

    /** 新增 */
    @ApiOperation(value = "新增")
    @PostMapping(value = "insert")
    public ResponseVO insert(@RequestBody @Validated DataDownInsertVO vo) {
        DataDown record = ConvertUtil.copyProperties(vo, DataDown.class);
        record.setCreateBy(getCurrentUser().getUsername());
        dataDownService.insert(record);
        return ResponseVO.success();
    }

    /** 删除 */
    @ApiOperation(value = "删除")
    @PostMapping(value = "delete")
    public ResponseVO delete(@RequestParam("id") Long id) {
        dataDownService.delete(id);
        return ResponseVO.success();
    }

    /** 修改 */
    @ApiOperation(value = "修改")
    @PostMapping(value = "update")
    public ResponseVO update(@RequestBody @Validated DataDownUpdateVO vo){
        DataDown record = ConvertUtil.copyProperties(vo, DataDown.class);
        record.setUpdateBy(getCurrentUser().getUsername());
        dataDownService.update(record);
        return ResponseVO.success();
    }

    /** 查询列表 */
    @ApiOperation(value = "查询列表")
    @PostMapping(value = "list")
    public ResponseVO list(DataDown record) {
        List<DataDown> list = dataDownService.list(record);
        return ResponseVO.success(list);
    }

}